package com.googlecode.garbagecan.dbtest.postgresql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestPostgreSQL {

	public static void main(String[] args) throws Exception {
		TestPostgreSQL t = new TestPostgreSQL();
		t.testConnection();
	}

	private void testConnection() throws Exception {
		Connection conn = this.getConnection();
		String sql = " select version()";
		PreparedStatement ps = conn.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			System.out.println(rs.getString(1));
		}
		rs.close();
		ps.close();
		conn.close();
	}

	private Connection getConnection() throws Exception {
		Class.forName("org.postgresql.Driver");
		String url = "jdbc:postgresql://172.17.18.211/fkong";
		Connection conn = DriverManager.getConnection(url, "fkong", "fkong");
		return conn;
	}
}
